/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO.Usuario;

import Model.User;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.hibernate.Session;

/**
 *
 * @author pedro
 */
@Path("/alteraCadastro")
public class AlteraCadastro {

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.TEXT_PLAIN)
    public Response alteraCadastro(User user) {
        Session session = null;
        String response;

        try {
            session = HibernateUtil.getSession();
            HibernateUtil.beginTransaction();
            session.update(user);
            HibernateUtil.commitTransaction();
            response="OK";
        } catch (Exception e) {
            System.out.println(e);
            response="Error";
            session.getTransaction().rollback();
        } finally {
            try {
                HibernateUtil.closeSession();
            } catch (Throwable e) {
                System.out.println(e.getMessage());
            }
        }
        return Response.status(201).entity(response).build();
    }
}
